package ai.people.core.standard.analysis.service.impl;

import ai.people.core.standard.analysis.service.AnalysisDataUserService;
import ai.people.core.standard.analysis.mapper.AnalysisDataUserMapper;
import ai.people.netmon.framework.domain.telegram.entity.AnalysisDataUser;
import ai.people.netmon.framework.exception.enums.CommonEnum;
import ai.people.netmon.framework.utils.AssertUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 分析数据用户服务
 *
 * @author yuanqinglong
 * @date 2022/3/9 11:27
 */
@Service
public class AnalysisDataUserServiceImpl implements AnalysisDataUserService {


    @Autowired
    private AnalysisDataUserMapper analysisDataUserMapper;




    /**
     * 添加分析数据
     *
     * @param analysisDataUser 分析数据用户
     */
    @Override
    public void addAnalysisData(AnalysisDataUser analysisDataUser) {
        int insert = analysisDataUserMapper.insert(analysisDataUser);
        AssertUtils.isTrue(insert > 0, CommonEnum.FAIL);
    }


    /**
     * 取消分析数据
     *
     * @param analysisDataUser 分析数据用户
     */
    @Override
    public void deleteAnalysisData(AnalysisDataUser analysisDataUser) {
        LambdaQueryWrapper<AnalysisDataUser> lambdaQuery = Wrappers.lambdaQuery(AnalysisDataUser.class);
        lambdaQuery.eq(AnalysisDataUser::getUserId,analysisDataUser.getUserId())
                   .eq(AnalysisDataUser::getAnalysisTargetId,analysisDataUser.getAnalysisTargetId())
                   .eq(AnalysisDataUser::getAnalysisType,analysisDataUser.getAnalysisType())
                   .eq(AnalysisDataUser::getAnalysisSource,analysisDataUser.getAnalysisSource());
        int delete = analysisDataUserMapper.delete(lambdaQuery);
        AssertUtils.isTrue(delete > 0, CommonEnum.FAIL);
    }


}
